package com.example.book_libapp;

import java.util.ArrayList;

import org.json.JSONObject;

import com.example.database.library.JSONParser;
import com.example.database.library.DatabaseHandler;
import com.example.database.library.UserFunctions;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ListViewBookActivity extends Activity {
	
	private static String url = "http://";
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.book_listview);
        
        ArrayList<Book> book_details = GetSearchResults();
        
        final ListView lv1 = (ListView) findViewById(R.id.listV_main);
        lv1.setAdapter(new BookListBaseAdapter(this, book_details));
        
        JSONParser jParser = new JSONParser();
        
        JSONObject json = jParser.getJSONFromUrl(url);
        
        lv1.setOnItemClickListener(new OnItemClickListener() {
        	@Override
        	public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
        		Object o = lv1.getItemAtPosition(position);
            	Book obj_Book = (Book)o;
        		
				Intent i = new Intent(getApplicationContext(), BookDetails.class);
				i.putExtra("id", position);
				startActivity(i);

        	}  
        });
    }
    
    private ArrayList<Book> GetSearchResults(){
    	ArrayList<Book> results = new ArrayList<Book>();
    	
    	Book item_details = new Book();
    	item_details.setName("Book");
    	item_details.setAuthor("ih unshigdasn");
    	item_details.setPrice("30000T");
    	item_details.setImageNumber(1);
    	results.add(item_details);
    	
    	item_details = new Book();
    	item_details.setName("Book1");
    	item_details.setAuthor("Google android");
    	item_details.setPrice("20000T");
    	item_details.setImageNumber(2);
    	results.add(item_details);
    	
    	item_details = new Book();
    	item_details.setName("Book 2 ");
    	item_details.setAuthor("anroid developer");
    	item_details.setPrice("39000T");
    	item_details.setImageNumber(3);
    	results.add(item_details);
    	
    	item_details = new Book();
    	item_details.setName("Android");
    	item_details.setAuthor("Android tutorials");
    	item_details.setPrice("38000T");
    	item_details.setImageNumber(4);
    	results.add(item_details);
    	
    	item_details = new Book();
    	item_details.setName("IPhone");
    	item_details.setAuthor("IPhone book");
    	item_details.setPrice("35000T");
    	item_details.setImageNumber(5);
    	results.add(item_details);
    	
    	item_details = new Book();
    	item_details.setName("PC book");
    	item_details.setAuthor("book");
    	item_details.setPrice("25000T");
    	item_details.setImageNumber(6);
    	results.add(item_details);
    	
    	
    	return results;
    }
}